package com.xhrd.demo.web.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;

import com.xhrd.demo.entities.Role;
import com.xhrd.demo.service.RoleService;
import com.xhrd.demo.vo.RoleSearchCondition;
import com.xhrd.framework.common.util.DateUtil;
import com.xhrd.framework.web.EntityController;

@Controller
@RequestMapping("/system/role/*")
public class RoleController extends EntityController<Role, RoleSearchCondition> {

    @Autowired
    private RoleService roleService;

    @Autowired
    public void setRoleService(RoleService service) {
        super.setEntityService(service);
    }

    public RoleController() {
        super();
        pathPrefix = "demo/";
    }

    /**
     * 转换页面提交来的日期格式
     */
    @InitBinder
    protected void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
        binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat(DateUtil.getDateTimePattern()), true));
    }

}
